package vip.meeet.mysql.jpa.repository;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.Repository;
import org.springframework.scheduling.annotation.Async;
import org.springframework.util.concurrent.ListenableFuture;
import vip.meeet.mysql.jpa.entity.User;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import java.util.stream.Stream;

public interface UserRepository extends Repository<User,Integer> {

//    List<User> findByUsername(String username);

    List<User> findByUsernameAndAge(String name,Integer age);

    List<User> findByUsernameLike(String username);

    List<User> findByIdIn(List<String> ids);

    List<User> findByIdInOrderByUsername(List<String> ids);

    void deleteByIdIn(List<String> ids);

    Long countByUsernameLike(String username);

//    Page<User> findByAge(Integer age,Pageable pageable);

    Slice<User> findByAge(Integer age, Pageable pageable);

    List<User> findByAge(Integer age,Sort sort);

    @Async
    Future<User> findByUsername(String username);

    @Async
    CompletableFuture<User> findOneByUsername(String username);

    @Async
    ListenableFuture<User> findOneByAge(Integer age);

    Stream<User> readAllByAgeAfter(Integer age);

}
